/**
 * @fileOverview A client-side implementation of CommonJS Modules 1.0
 * @author Renaat De Muynck
 * @since 12-2011
 */
var require = (function () {
    var cache = {},
        curDir,
        appRoot;
    
    
    /**
     * Loads the script from the server
     */
    function loadScript(url) {
        var xhr = new XMLHttpRequest(),
            fn,
            exports = {};
        // download the requested file synchronously
        xhr.open('get', url, false);
        xhr.send();
        // throw an error if the file could not be downloaded
        if (!(xhr.status >= 200 && xhr.status < 300) && xhr.status !== 304) {
            throw new Error('The requested file could not be downloaded');
        }
        // check if the downloaded file is a javascript file
        if (xhr.getResponseHeader('Content-Type') !== 'application/x-javascript') {
            throw new Error('The requested file is not a javascript file');
        }
        // 
        fn = new Function('exports', xhr.responseText);
        // store the module in the cache
        cache[url] = fn.call(null, exports);
    }
    /**
     *
     */
    function resolve(module) {
        return module;
    }
    /**
     *
     */
    function require(module) {
        console.info('about to load module: ', module);
        //
        var url = resolve(module);
        //
        if (!Object.prototype.hasOwnProperty.call(cache, url)) {
            loadScript(url);
        }
        //
        return cache[url];
    }
    //
    require.cache = cache;
    require.resolve = resolve;
    //
    return require;
}());
